//
//  MCSettingViewController.m
//  MicroChat
//
//  Created by Mac on 2018/5/28.
//  Copyright © 2018年 stoneobs.qq.com. All rights reserved.
//

#import "MCSettingViewController.h"
#import "TMLoginViewController.h"
#import "MCNewMessageAlertViewController.h"
#import "MCAboutUsViewController.h"
#import "MCSugesstViewController.h"
@interface MCSettingViewController ()
@property(nonatomic, strong) NSArray                     *dataSouce;/**< <##> */
@end

@implementation MCSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    [self configSubView];
    // Do any additional setup after loading the view.
}
#pragma mark --subView
- (void)configSubView{
    NSArray * section0 = @[
                           [[STTableEasyModel alloc] initWithTextString:@"意见反馈" imageName:@""],
                           [[STTableEasyModel alloc] initWithTextString:@"关于轻聊" imageName:@""],
                           [[STTableEasyModel alloc] initWithTextString:@"新消息提醒" imageName:@""],
                           ];
    
    NSArray * section1 = @[
                           [[STTableEasyModel alloc] initWithTextString:@"退出登录" imageName:@""],
                           ];
    self.dataSouce = @[section0,section1];
    [self.tableView reloadData];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [self.dataSouce[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    cell.textLabel.textColor = UIColorFromRGBA(0x333333);
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
    cell.detailTextLabel.textColor = UIColorFromRGBA(0x999999);
    
    STTableEasyModel * mdoel = self.dataSouce[indexPath.section][indexPath.row];
    [cell setSt_tableEasyModel:mdoel];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * mdoel = self.dataSouce[indexPath.section][indexPath.row];
    if ([mdoel.textString isEqualToString:@"退出登录"]) {
        [self showAlertCancelAndConfirm:@"确定要退出登录吗?" andWithBlock:^(NSString *name) {
            if ([name isEqualToString:@"确认"]) {
                [[STUserManger defult] removeUserPreferce];
                [UIApplication sharedApplication].keyWindow.rootViewController = [[STNavigationController alloc] initWithRootViewController:[TMLoginViewController new]];
                [[UIApplication sharedApplication].keyWindow st_showAnimationWithType:STAnimationTypecube];
            }
        }];
    }
    if ([mdoel.textString isEqualToString:@"新消息提醒"]) {
        MCNewMessageAlertViewController * vc = [MCNewMessageAlertViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([mdoel.textString isEqualToString:@"关于轻聊"]) {
        MCAboutUsViewController * vc = [MCAboutUsViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([mdoel.textString isEqualToString:@"意见反馈"]) {
        MCSugesstViewController * vc = [MCSugesstViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
@end
